package model;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Jenni Mercado
 *
 *  Checks whether a file is of an supported file type
 */

public class FileChecker {

    private List<String> mySupportedFileTypes;

    /**
     * Takes a list of file types (in form ".[file_type]") and lists those as
     * supported types.
     *
     * @param fileTypes List of acceptable file formats
     */
    public FileChecker (List<String> fileTypes) {
        mySupportedFileTypes = new ArrayList<String>();
        for (String fileType : fileTypes) {
            mySupportedFileTypes.add(fileType);
        }
    }

    /**
     * Returns whether a given File is of an accepted file type.
     *
     * @param dataFile Data File to be checked
     * @return dataType String ending of data file, or null string if file type
     *         not supported
     */
    public String isSupported (File dataFile) {
        String[] temp = dataFile.getName().split("\\.");
        String dataType = temp[temp.length - 1];
        for (String fileType : mySupportedFileTypes) {
            if (fileType.equals(dataType)) { return dataType; }
        }
        return null;
    }

}
